<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/28/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/28/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/02/08/PyCharm+Qt%20Designer+PyUIC%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/02/08/PyCharm+Qt%20Designer+PyUIC%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/" class="post-title-link" itemprop="url">PyCharm+Qt Designer+PyUIC配置教程</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-02-08 14:31:31" itemprop="dateCreated datePublished" datetime="2021-02-08T14:31:31+08:00">2021-02-08</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/QT/" itemprop="url" rel="index"><span itemprop="name">QT</span></a>
                </span>
            </span>

          
            <span id="/2021/02/08/PyCharm+Qt%20Designer+PyUIC%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/" class="post-meta-item leancloud_visitors" data-flag-title="PyCharm+Qt Designer+PyUIC配置教程" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/02/08/PyCharm+Qt%20Designer+PyUIC%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/02/08/PyCharm+Qt%20Designer+PyUIC%E9%85%8D%E7%BD%AE%E6%95%99%E7%A8%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p><strong>pycharm添加designer</strong></p>
<p>​    在Settings界面Tools-&gt;External Tools里添加designer工具：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image2.png"></p>
<p><strong>pycharm添加pyuic</strong></p>
<p>​    同样的位置，添加pyuic</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image3.png"></p>
<p>​    Arguments里填入$FileName$ -o $FileNameWithoutExtension$.py</p>
<p>​    Working directory里填$ProjectFileDir$即可。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/02/08/PyQt5%20ImportError%EF%BC%9ADLL%20load%20failed%EF%BC%9A%E6%89%BE%E4%B8%8D%E5%88%B0%E6%8C%87%E5%AE%9A%E6%A8%A1%E5%9D%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/02/08/PyQt5%20ImportError%EF%BC%9ADLL%20load%20failed%EF%BC%9A%E6%89%BE%E4%B8%8D%E5%88%B0%E6%8C%87%E5%AE%9A%E6%A8%A1%E5%9D%97/" class="post-title-link" itemprop="url">PyQt5 ImportError：DLL load failed：找不到指定模块</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-02-08 14:23:06" itemprop="dateCreated datePublished" datetime="2021-02-08T14:23:06+08:00">2021-02-08</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/QT/" itemprop="url" rel="index"><span itemprop="name">QT</span></a>
                </span>
            </span>

          
            <span id="/2021/02/08/PyQt5%20ImportError%EF%BC%9ADLL%20load%20failed%EF%BC%9A%E6%89%BE%E4%B8%8D%E5%88%B0%E6%8C%87%E5%AE%9A%E6%A8%A1%E5%9D%97/" class="post-meta-item leancloud_visitors" data-flag-title="PyQt5 ImportError：DLL load failed：找不到指定模块" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/02/08/PyQt5%20ImportError%EF%BC%9ADLL%20load%20failed%EF%BC%9A%E6%89%BE%E4%B8%8D%E5%88%B0%E6%8C%87%E5%AE%9A%E6%A8%A1%E5%9D%97/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/02/08/PyQt5%20ImportError%EF%BC%9ADLL%20load%20failed%EF%BC%9A%E6%89%BE%E4%B8%8D%E5%88%B0%E6%8C%87%E5%AE%9A%E6%A8%A1%E5%9D%97/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p><strong>问题描述</strong></p>
<p>​    运行环境 ： pycharm + anaconda+ python3.7</p>
<p>​    出现问题：使用QT Designer创建完.ui文件后无法使用pyUIC进行转换</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image.png"></p>
<p><strong>原因</strong></p>
<p>​    Anaconda中自带的pyqt库与base环境出现不可描述的问题，推测是pyqt版本问题！</p>
<p><strong>解决办法</strong></p>
<p>​    安装最新版PyQt5,但是直接pip install pyqt5速度非常慢，可以先把文件下载下来然后直接安装。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%AE%89%E8%A3%85QT%E6%9C%89%E9%97%AE%E9%A2%98.png"></p>
<p>​    安装的时候显示拒绝访问，改用下面的安装指令即可：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20210208110523.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/02/04/MCU%E4%B9%8B%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E8%AE%BF%E9%97%AE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/02/04/MCU%E4%B9%8B%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E8%AE%BF%E9%97%AE/" class="post-title-link" itemprop="url">MCU之内存对齐访问</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-02-04 20:50:26" itemprop="dateCreated datePublished" datetime="2021-02-04T20:50:26+08:00">2021-02-04</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2021/02/04/MCU%E4%B9%8B%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E8%AE%BF%E9%97%AE/" class="post-meta-item leancloud_visitors" data-flag-title="MCU之内存对齐访问" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/02/04/MCU%E4%B9%8B%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E8%AE%BF%E9%97%AE/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/02/04/MCU%E4%B9%8B%E5%86%85%E5%AD%98%E5%AF%B9%E9%BD%90%E8%AE%BF%E9%97%AE/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="对齐访问"><a href="#对齐访问" class="headerlink" title="对齐访问"></a>对齐访问</h2><p>​    uint8_t定义变量地址要1字节对齐。<br>​    uint16_t定义变量地址要2字节对齐。<br>​    uint32_t定义变量地址要4字节对齐。<br>​    uint64_t定义变量地址要8字节对齐。</p>
<p>​    注：比如4字节对齐的含义就是变量地址对4求余数为0； 8字节对齐就是地址对8求余等于0；</p>
<p>​    程序里面直接定义是没问题的，如果是指针变量就要注意了。</p>
<p>​    比如<br>​    uint32_t *p;<br>​    p=(uint32_t *)0x24000004; 这个地址是4字节对齐。</p>
<p>​    如果让p去访问0x24000001， 0x24000002，0x24000003这都不是对齐的。</p>
<h2 id="具体例子"><a href="#具体例子" class="headerlink" title="具体例子"></a>具体例子</h2><p>​    这几天逛论坛，看到TopSemic 写的一个很好的例子，是在STM32F0上面写的一段程序。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span>  <span class="title">Struct_Def</span> &#123;</span></span><br><span class="line"><span class="keyword">uint8_t</span>    Var_B;</span><br><span class="line"><span class="keyword">uint16_t</span>   Var_W0;</span><br><span class="line"><span class="keyword">uint16_t</span>   Var_W1;</span><br><span class="line"><span class="keyword">uint32_t</span>   Var_DW;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="class"><span class="keyword">struct</span>  <span class="title">Struct_Def</span> <span class="title">My_Struct</span>;</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">My_Struct.Var_B  = <span class="number">0x01</span>;</span><br><span class="line">My_Struct.Var_W0 = <span class="number">0x0203</span>;</span><br><span class="line">My_Struct.Var_W1 = <span class="number">0x0405</span>;</span><br><span class="line">My_Struct.Var_DW = <span class="number">0x06070809</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​    在内存中的布局如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210204203218.png" style="zoom:67%;">

<p>​    编译器在Var_B之后插入了一个字节，在Var_W1之后插入了两个字节。这个结构体在内存中实际占用了 1 + 1 + 2 + 2 + 2 + 4 = 12 Bytes 。为什么会这样呢？这是 ARM Cortex M0体系决定的，它只支持对齐访问 ( Aligned Access )。比如我们访问一个4字节 (Double Word) 型的变量时，如果这个变量的起始地址是能被4整除的话，我们说这种访问是双字节对齐的。如果访问一个2字节 ( Word ) 变量，当起始地址能被2整除时是对齐的。访问字节 ( Byte ) 型变量，总是对齐的。</p>
<p>​    大家看一下例子中的这一个赋值语句：My_Struct.Var_DW = 0x06070809;</p>
<p>​    它是一个4字节 ( Double Word ) 型的变量赋值。Var_DW这个成员，如果按照在结构体中的顺序，应该紧随Var_W1之后，分配在 0x20000012，但是这个地址是不能被4整除的，所以编译器在填充了2个字节0之后，把Var_DW的起始地址分配在了0x20000014 。</p>
<h2 id="非对齐访问"><a href="#非对齐访问" class="headerlink" title="非对齐访问"></a>非对齐访问</h2><p>​    我们可以用到伪指令#pragma pack ，如下例所示，#pragma pack(1) 将会使结构体中的变量一个字节紧挨着一个字节在内存中分配。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> pack(1)</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span>  <span class="title">Struct_Def</span> </span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line"><span class="keyword">uint8_t</span>    Var_B;</span><br><span class="line"><span class="keyword">uint16_t</span>   Var_W0;</span><br><span class="line"><span class="keyword">uint16_t</span>   Var_W1;</span><br><span class="line"><span class="keyword">uint32_t</span>   Var_DW;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="class"><span class="keyword">struct</span>  <span class="title">Struct_Def</span> <span class="title">My_Struct</span>;</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">pragma</span> pack()</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">volatile</span> <span class="keyword">uint32_t</span> Test_Var;</span><br><span class="line"><span class="comment">// 非对齐访问，进入 HardFault :</span></span><br><span class="line">Test_Var = *(<span class="keyword">uint32_t</span> *)(&amp;My_Struct.Var_DW);</span><br></pre></td></tr></table></figure>
<p>​    我手头没有stm32f0的板子，所以就用stm32f4试了一下，竟然没有HardFault，什么鬼？怎么和上面的现象不一样呢?后来查阅了一下资料，发现是因为M3和M4支持非对齐的内存访问，如下图所示：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210204204920.jpg"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/02/04/USB%E4%B9%8B%E4%BC%A0%E8%BE%93+%E4%BA%8B%E5%8A%A1+%E5%8C%85/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/02/04/USB%E4%B9%8B%E4%BC%A0%E8%BE%93+%E4%BA%8B%E5%8A%A1+%E5%8C%85/" class="post-title-link" itemprop="url">USB之传输+事务+包</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-02-04 15:10:25" itemprop="dateCreated datePublished" datetime="2021-02-04T15:10:25+08:00">2021-02-04</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/USB/" itemprop="url" rel="index"><span itemprop="name">USB</span></a>
                </span>
            </span>

          
            <span id="/2021/02/04/USB%E4%B9%8B%E4%BC%A0%E8%BE%93+%E4%BA%8B%E5%8A%A1+%E5%8C%85/" class="post-meta-item leancloud_visitors" data-flag-title="USB之传输+事务+包" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/02/04/USB%E4%B9%8B%E4%BC%A0%E8%BE%93+%E4%BA%8B%E5%8A%A1+%E5%8C%85/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/02/04/USB%E4%B9%8B%E4%BC%A0%E8%BE%93+%E4%BA%8B%E5%8A%A1+%E5%8C%85/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="1-USB传输类型"><a href="#1-USB传输类型" class="headerlink" title="1. USB传输类型"></a>1. USB传输类型</h2><p>​    USB传输有四种类型，包括<strong>控制传输</strong>、<strong>同步传输</strong>、<strong>批量传输</strong>、<strong>中断传输</strong>，每种传输类型使用的事务类型也有所不同。其中同步传输、批量传输每次传输需要一个或多个事务，中断传输每次传输只需要一个事务。</p>
<h3 id="1-1控制传输"><a href="#1-1控制传输" class="headerlink" title="1.1控制传输"></a>1.1控制传输</h3><p>​    控制传输包括<strong>控制读传输</strong>、<strong>控制写传输</strong>、<strong>无数据的控制传输</strong>，主机在枚举设备的时候，首先进行插入检测，检测完毕之后，设备采用0号端点，以默认地址和主机进行控制传输来进行数据交互，进行传输的通道叫做控制管道。</p>
<h3 id="1-2同步传输"><a href="#1-2同步传输" class="headerlink" title="1.2同步传输"></a><strong>1.2同步传输</strong></h3><p>​    <strong>同步传输使用同步事务（Isochronous Transactions）</strong>来传输数据。同步传输用在数据量大、对实时性要求高的场合，例如音频设备、视屏设备等，这些设备对数据延时敏感。</p>
<p>​    这种事务能保证传输的同步性。例如在USB摄像头中传输视频数据的时候会采用这种事务，这种事务能保证每秒有固定的数量传输带宽，但与Bulk传输不同，同步允许有一定的误码率，这样符合视频会议等传输的需求，因为视频会议首先要保证实时性，在一定条件下，允许有一定的误码率。</p>
<p>​    同步传输事务有只有两个阶段，即令牌阶段、数据阶段，因为不关心数据的正确性，<strong>故没有握手阶段，这边的令牌阶段、数据阶段、握手阶段准确的说其实是指的是令牌包、数据包、握手包。</strong></p>
<h3 id="1-3批量传输"><a href="#1-3批量传输" class="headerlink" title="1.3批量传输"></a><strong>1.3批量传输</strong></h3><p>​    <strong>批量传输是使用批量事务（Bulk Transactions）来传输数据</strong>。批量传输分为批量读传输和批量写传输两种。批量读使用批量输入事务，批量写使用批量输出事务。批量传输通常在数据量大、对数据的实时性要求不高的场合，例如USB打印机、扫描仪、大容量存储设备等。</p>
<h3 id="1-4中断传输"><a href="#1-4中断传输" class="headerlink" title="1.4中断传输"></a><strong>1.4中断传输</strong></h3><p>​    <strong>中断传输是使用中断事务（Interrupt Transactions）来传输数据的</strong>。中断传输是一种可以保证主机查询频率的传输。中断端点在端点描述符中要报告主机对此端点的查询时间，主机会保证在小于这个时间间隔的范围内安排一次传输，比如HOST主机1ms内向鼠标设备请求一次数据。</p>
<h2 id="2-USB事务"><a href="#2-USB事务" class="headerlink" title="2. USB事务"></a>2. USB事务</h2><p>​    不同种的传输由不同的事务组成，其中批量传输、同步传输每次传输需要一个或多个事务，中断传输一次需要一个事务，控制传输包括三个过程（<strong>建立过程、数据过程、状态过程</strong>），建立过程和状态过程分别需要一个事务<strong>，</strong>数据过程则可能包含0个多个事务。看实例协议分析，要知道<strong>transfer是传输</strong>，<strong>transaction为事务。</strong></p>
<p>​    事务有三种类型，Setup事务、Data IN事务、Data OUT事务。</p>
<ul>
<li>Setup事务：主要向设备发送控制命令；</li>
<li>Data In事务：主要从设备读取数据；</li>
<li>Data OUT事务：主要向设备发送数据。</li>
</ul>
<p>​    下面的图都来自于CSDN博主“<a target="_blank" rel="noopener" href="https://hellocode.blog.csdn.net/">一个早起的程序员</a>”，非常感谢他，本文的大部分内容基本都来自于他的博客，通过这几个图可以加深我们的理解。</p>
<p>1.批量传输（由一个事务组成）</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210104225901978.png"></p>
<p>2.同步传输（由一个事务组成）</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210104230052841.png"></p>
<p>3.中断传输（由一个事务组成）</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210104230306688.png"></p>
<p>4.控制传输（建立过程和状态过程由1个事务组成，数据过程由0个或者多个事务组成）</p>
<p>控制写传输：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210104231608885.png"></p>
<p>控制读传输：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210104231323370.png"></p>
<p>无数据控制传输：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210104231107223.png"></p>
<h2 id="3-USB包"><a href="#3-USB包" class="headerlink" title="3. USB包"></a>3. USB包</h2><p>​    USB所有类型的事务（Setup事务、IN事务、OUT事务）都是由3个包组成（令牌包Token packet、数据包Data packet、握手包Handshack packet），<strong>但是同步传输事务由2个包组成</strong>（令牌包、数据包），没有握手包，不会再有其他可能。</p>
<h2 id="4-传输、事务、包组成学习架构图"><a href="#4-传输、事务、包组成学习架构图" class="headerlink" title="4.传输、事务、包组成学习架构图"></a>4.传输、事务、包组成学习架构图</h2><p>​        CSDN博主“<a target="_blank" rel="noopener" href="https://hellocode.blog.csdn.net/">一个早起的程序员</a>”提供了一张图可以很清楚的表示这三个概念之间的关系，如下所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/7a3d4e8cdef389523b17f02ddeac5881.png" style="zoom:58%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/02/01/%E7%BC%96%E8%AF%91libwdi/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/02/01/%E7%BC%96%E8%AF%91libwdi/" class="post-title-link" itemprop="url">编译libwdi</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-02-01 09:28:42" itemprop="dateCreated datePublished" datetime="2021-02-01T09:28:42+08:00">2021-02-01</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/USB/" itemprop="url" rel="index"><span itemprop="name">USB</span></a>
                </span>
            </span>

          
            <span id="/2021/02/01/%E7%BC%96%E8%AF%91libwdi/" class="post-meta-item leancloud_visitors" data-flag-title="编译libwdi" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/02/01/%E7%BC%96%E8%AF%91libwdi/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/02/01/%E7%BC%96%E8%AF%91libwdi/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="1-安装Visual-Studio和WDK"><a href="#1-安装Visual-Studio和WDK" class="headerlink" title="1.安装Visual Studio和WDK"></a>1.安装Visual Studio和WDK</h2><h3 id="1-1-安装Visual-Studio-2019社区版"><a href="#1-1-安装Visual-Studio-2019社区版" class="headerlink" title="1.1 安装Visual Studio 2019社区版"></a>1.1 安装Visual Studio 2019社区版</h3><p>​    安装 Visual Studio 2019时，选择“使用 C++ 的桌面开发”工作负荷。Windows 10 软件开发工具包 (SDK) 会自动包括在内，并显示在右侧的“摘要”窗格中。因为下面还要用到WDK，但是默认安装的SDK版本可能和WDK不兼容。</p>
<p>​     如果已安装Visual Studio 2019，则可以使用 Visual Studio 安装中的“修改”按钮来安装 Windows 10 SDK (10.0.19041.0)。在 Visual Studio 安装程序中的“单个组件”选项卡上，搜索“Windows 10 SDK (10.0.19041.0)”，选择此版本，然后继续安装。</p>
<h3 id="1-2-Windows-Driver-Kit-WDK-10"><a href="#1-2-Windows-Driver-Kit-WDK-10" class="headerlink" title="1.2 Windows Driver Kit (WDK) 10"></a>1.2 Windows Driver Kit (WDK) 10</h3><p>​    遗憾的是，libwdi编译库所需的WinUSB可再发行文件已不再作为独立下载由微软提供，因此我们需要下载并安装最新的Windows Driver Kit。</p>
<ul>
<li><a target="_blank" rel="noopener" href="https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit">https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit</a> ，下载适用于Windows10版本2004的WDK。</li>
<li>点击wdksetup.exe，安装Windows Driver Kit在本机上。</li>
</ul>
<h2 id="2-获取最新的libwdi-source"><a href="#2-获取最新的libwdi-source" class="headerlink" title="2. 获取最新的libwdi source"></a>2. 获取最新的libwdi source</h2><p>​    <a target="_blank" rel="noopener" href="https://github.com/pbatard/libwdi.git">https://github.com/pbatard/libwdi.git</a> 获取最新的源代码。</p>
<h2 id="3-编译libwdi"><a href="#3-编译libwdi" class="headerlink" title="3. 编译libwdi"></a>3. 编译libwdi</h2><p>​    用VS2019打开libwdi.sln工程，终于开始编译和调试libwdi应用程序了。但是，我们需要修改其中一个源文件，因为我们唯一可用的驱动程序（通过WDK 10安装）是WinUSB，而且默认情况下，libwdi还希望libusb-win32和libusbK驱动程序可用。</p>
<p>​    在embedder-&gt;Header Files-&gt;config.h文件中，找到下面的代码片段，将定义的宏注释掉：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210131134422.png" style="zoom:60%;">

<p>​    在菜单栏上选择Build-&gt;Build Solution。编译的时候会用到Windows Kits里面的库，工程默认会去C盘下找，所以安装Windows Kits的时候建议安装在默认的位置。编译的输出窗口如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/20210131142624.png" style="zoom:50%;">

<p>到这里就编译成功了，最终的库和例子可以在<arch>/&lt;Release|Debug&gt;中找到。</arch></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/01/25/Pycharm%E6%89%93%E5%8C%85exe%E6%96%87%E4%BB%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/01/25/Pycharm%E6%89%93%E5%8C%85exe%E6%96%87%E4%BB%B6/" class="post-title-link" itemprop="url">Pycharm打包exe文件</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-25 14:57:58" itemprop="dateCreated datePublished" datetime="2021-01-25T14:57:58+08:00">2021-01-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2021/01/25/Pycharm%E6%89%93%E5%8C%85exe%E6%96%87%E4%BB%B6/" class="post-meta-item leancloud_visitors" data-flag-title="Pycharm打包exe文件" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/01/25/Pycharm%E6%89%93%E5%8C%85exe%E6%96%87%E4%BB%B6/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/01/25/Pycharm%E6%89%93%E5%8C%85exe%E6%96%87%E4%BB%B6/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="1-安装Pyinstaller"><a href="#1-安装Pyinstaller" class="headerlink" title="1.安装Pyinstaller"></a>1.安装Pyinstaller</h2><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install  PyInstaller</span><br></pre></td></tr></table></figure>
<h2 id="2-打包程序"><a href="#2-打包程序" class="headerlink" title="2. 打包程序"></a>2. 打包程序</h2><p>​    进入到文件夹所在的路径，执行下面这条指令：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pyinstaller -F -w -i tubiao.ico 文件名.py</span><br></pre></td></tr></table></figure>
<p>​    -F 表示生成单个可执行文件</p>
<p>​    -w 表示去掉控制台窗口，这在GUI界面时非常有用。不过如果是命令行程序的话那就把这个选项删除吧！</p>
<p>​    -p 表示你自己自定义需要加载的类路径，一般情况下用不到。</p>
<p>​    -i 表示可执行文件的图标。</p>
<h2 id="3-生成的可执行程序所在路径"><a href="#3-生成的可执行程序所在路径" class="headerlink" title="3. 生成的可执行程序所在路径"></a>3. 生成的可执行程序所在路径</h2><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210125145707.png" style="zoom:67%;">
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/01/25/USB%E7%9A%84%E6%8F%8F%E8%BF%B0%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/01/25/USB%E7%9A%84%E6%8F%8F%E8%BF%B0%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB/" class="post-title-link" itemprop="url">USB的描述符及其之间的关系</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-25 11:37:19" itemprop="dateCreated datePublished" datetime="2021-01-25T11:37:19+08:00">2021-01-25</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/USB/" itemprop="url" rel="index"><span itemprop="name">USB</span></a>
                </span>
            </span>

          
            <span id="/2021/01/25/USB%E7%9A%84%E6%8F%8F%E8%BF%B0%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB/" class="post-meta-item leancloud_visitors" data-flag-title="USB的描述符及其之间的关系" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/01/25/USB%E7%9A%84%E6%8F%8F%E8%BF%B0%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/01/25/USB%E7%9A%84%E6%8F%8F%E8%BF%B0%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E5%85%B3%E7%B3%BB/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​    下面的内容主要都来源于《圈圈教你玩USB》这一本书以及网友的博客：<a target="_blank" rel="noopener" href="https://blog.csdn.net/sz189981/article/details/62072621?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-3&amp;spm=1001.2101.3001.4242%E3%80%82">https://blog.csdn.net/sz189981/article/details/62072621?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-3&amp;spm=1001.2101.3001.4242。</a></p>
<h2 id="1-USB描述符的作用"><a href="#1-USB描述符的作用" class="headerlink" title="1. USB描述符的作用"></a><strong>1. USB描述符的作用</strong></h2><p>  告诉USB主机，USB设备的功能及行为。</p>
<p>  描述符中记录了设备的类型、厂商ID和产品ID(通常依靠它们来加载对应的驱动程序)、端点的情况、版本号等众多信息。</p>
<h2 id="2-标准描述符"><a href="#2-标准描述符" class="headerlink" title="2. 标准描述符"></a><strong>2. 标准描述符</strong></h2><p>  USB1.1协议定义的：① 设备描述符 ② 配置描述符 ③ 接口描述符 ④ 端点描述符 ⑤ 字符串描述符</p>
<p>  USB2.0协议增加的：⑥ 设备质量描述符 ⑦ 其它速度配置描述符</p>
<h2 id="3-特殊描述符"><a href="#3-特殊描述符" class="headerlink" title="3. 特殊描述符"></a><strong>3. 特殊描述符</strong></h2><p>  类特殊描述符：① HID描述符 ② 音频接口描述符</p>
<p>  厂商自定义的描述符等。</p>
<h2 id="4-USB描述符之间的层级关系"><a href="#4-USB描述符之间的层级关系" class="headerlink" title="4. USB描述符之间的层级关系"></a><strong>4. USB描述符之间的层级关系</strong></h2><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210125093934.png" style="zoom:60%;">

<p>​    设备描述符里决定 -&gt; 设备有几种配置描述符；</p>
<p>​    每种配置描述符里决定 -&gt; 该配置有几个接口；</p>
<p>​    每个接口描述符里定义 -&gt; 该接口有几个端点；(如果有类特殊描述符，跟在接口描述符之后)</p>
<p>​    端点描述符里定义了端点的大小和类型等。</p>
<h2 id="5-主机获取描述符的顺序-从上到下"><a href="#5-主机获取描述符的顺序-从上到下" class="headerlink" title="5. 主机获取描述符的顺序(从上到下)"></a><strong>5. 主机获取描述符的顺序(从上到下)</strong></h2><p>  ① 设备描述符；</p>
<p>  ② 配置描述符；</p>
<p>  ③ 配置描述符、接口描述符、类特殊描述符(如果有)、端点描述符；(主机根据配置描述符中配置集合的总长度，一次将它们读回)</p>
<p>  ④ 字符串描述符。(主机通过发送获取字符串描述符的请求、描述符的索引号、语言ID来单独获取对应的字符串描述符)</p>
<h2 id="6-描述符主要记录的信息"><a href="#6-描述符主要记录的信息" class="headerlink" title="6. 描述符主要记录的信息"></a><strong>6. 描述符主要记录的信息</strong></h2><table>
<thead>
<tr>
<th>序号</th>
<th>描述符</th>
<th>主要记录的信息</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>设备描述符</td>
<td>设备所使用的USB协议版本号、设备类型、端点0的最大包大小、厂商ID(VID)和产品ID(PID)、设备版本号、厂商字符串索引、产品字符串索引、设备序列号索引、可能的配置数等。</td>
</tr>
<tr>
<td>2</td>
<td>配置描述符</td>
<td>配置所包含的接口数、配置的编号、供电方式、是否支持远程唤醒、电流需求量等。</td>
</tr>
<tr>
<td>3</td>
<td>接口描述符</td>
<td>接口的编号、接口的端点数目、接口所使用的类、子类、协议等</td>
</tr>
<tr>
<td>4</td>
<td>端点描述符</td>
<td>端点号及方向、端点传输类型、最大包长度、查询时间间隔等</td>
</tr>
<tr>
<td>5</td>
<td>字符串描述符</td>
<td>方便人们阅读的信息，它不是必需的</td>
</tr>
</tbody></table>
<h2 id="7-USB-设备各属性的关系和设备各属性-VS-教室"><a href="#7-USB-设备各属性的关系和设备各属性-VS-教室" class="headerlink" title="7. USB 设备各属性的关系和设备各属性 VS 教室"></a><strong>7. USB 设备各属性的关系和设备各属性 VS 教室</strong></h2><table>
<thead>
<tr>
<th></th>
<th>USB设备：鼠标</th>
<th>USB设备：鼠标</th>
<th>教室</th>
<th>教室</th>
</tr>
</thead>
<tbody><tr>
<td>序号</td>
<td>属性</td>
<td>作用</td>
<td>属性</td>
<td>作用</td>
</tr>
<tr>
<td>1</td>
<td>设备地址：8888</td>
<td>找到设备</td>
<td>8号楼</td>
<td>找到楼</td>
</tr>
<tr>
<td>2</td>
<td>端点：0、1</td>
<td>找到端点</td>
<td>808教室</td>
<td>找到教室</td>
</tr>
<tr>
<td>3</td>
<td>配置(抽象概念，方便管理端点)</td>
<td>管理一个或多个不同的功能</td>
<td>教学楼的作用</td>
<td>用于期末考试(一个功能)或平时上课(多个功能)</td>
</tr>
<tr>
<td>4</td>
<td>接口(抽象概念，方便管理端点)</td>
<td>管理端点功能</td>
<td>教室的作用</td>
<td>考试或“上课和教师休息”</td>
</tr>
</tbody></table>
<p>​    ① 一个设备可以有多个配置，但同一个时刻只能有一个配置有效，当我们需要不同功能时，只需要选择不同配置即可；</p>
<p>​    ② 每个配置下可以有一个或多个接口；</p>
<p>​    ③ 每个接口下可以有一个或多个端点；</p>
<p>​    ④ 同一个端点号不能出现在同一个配置下两个或多个不同的接口中；但是可以用在不同的配置中。</p>
<p><strong>USB复合设备：</strong></p>
<p>​    具有多个接口并由接口实现功能的设备，例如一个USB音频设备，它具有 一个音频控制接口、一个到多个音频流或MIDI流接口。</p>
<p>​    在主机端会把USB复合设备的每一个接口当作一个功能设备看待。</p>
<p><strong>单一的设备</strong>：</p>
<p>​    一个设备下只有一个配置描述符、一个接口描述符，像常见的USB鼠标、U盘等。</p>
<h2 id="8-USB通讯中端点的概念"><a href="#8-USB通讯中端点的概念" class="headerlink" title="8. USB通讯中端点的概念"></a>8. USB通讯中端点的概念</h2><p>​    端点位于USB 外设内部，所有通信数据的来源或目的都基于这些端点，是一个可寻址的FIFO。</p>
<p>​    每个USB设备都有一个唯一的设备地址，设备地址是设备连接上主机时由主机分配的，主机主要依靠这个设备地址对USB设备进行访问。但是在设备内部地址会被分的更细，设备会分出一些端点来，每个端点在设备都会有唯一的端点号，这个端点号是设计设备时给定的。如端点0，端点1等。一个设备最多可以包含16个端点，每个端点的地址为0-15。</p>
<p>  其中每个端点地址对应一个方向。例如端点3-IN，端点3-OUT,这两个含义完全不同。但是需要注意其中的一个特殊端点–端点0，<strong>每个USB设备必须要有一个端点0</strong>，其作用为对设备枚举和对设备进行一些基本的控制功能，端点0也被称为控制端点。并且它与其他的端点还有一个不同之处在于<strong>端点0的数据传输方向是双向的</strong>，即端点0既可以给主机发送数据，也可以接收主机发送过来的数据，而其它端点均为单向。</p>
<p>   虽然有16个端点，但通常我们只用到3个,如下：</p>
<p>   1）、EP0：做传输配置和控制信息；</p>
<p>   2）、EP1：做数据输入IN_EP；</p>
<p>   3）、EP2：做数据输出OUT_EP。</p>
<p><strong>注意：</strong>除了端点0，其余的端点在设备配置之前不能与主机通信，只有向主机报告这些端点的特性并被确认后才能被激活。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/01/24/Jetson%20nano%20gstreamer%E8%A7%86%E9%A2%91%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/01/24/Jetson%20nano%20gstreamer%E8%A7%86%E9%A2%91%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81/" class="post-title-link" itemprop="url">Jetson nano gstreamer视频编码和解码</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-24 13:57:28" itemprop="dateCreated datePublished" datetime="2021-01-24T13:57:28+08:00">2021-01-24</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Jetson/" itemprop="url" rel="index"><span itemprop="name">Jetson</span></a>
                </span>
            </span>

          
            <span id="/2021/01/24/Jetson%20nano%20gstreamer%E8%A7%86%E9%A2%91%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81/" class="post-meta-item leancloud_visitors" data-flag-title="Jetson nano gstreamer视频编码和解码" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/01/24/Jetson%20nano%20gstreamer%E8%A7%86%E9%A2%91%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/01/24/Jetson%20nano%20gstreamer%E8%A7%86%E9%A2%91%E7%BC%96%E7%A0%81%E5%92%8C%E8%A7%A3%E7%A0%81/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="0-软件安装"><a href="#0-软件安装" class="headerlink" title="0. 软件安装"></a>0. 软件安装</h2><p>​    Jetson nano上默认已经安装了gstreamer，但是pip是没有安装的，我这边用python3，因此安装：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install python3-pip</span><br></pre></td></tr></table></figure>
<p>​    安装Jetson-Stats,这个工具可以让我们知道已经安装的Jetpack的版本是多少，GPU使用率，CPU用了几个等等问题。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo -H pip3 install -U jetson-stats</span><br><span class="line">sudo jtop</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信图片_20210124100741.jpg" style="zoom:30%;">

<h2 id="1-视频压缩的目的"><a href="#1-视频压缩的目的" class="headerlink" title="1. 视频压缩的目的"></a>1. 视频压缩的目的</h2><p>​    在实时系统中，视频传输的帧速率和延迟比较重要，通常使用以太网、无线局域网来发送或存储未压缩的视频，未压缩的视频需要大量带宽。720p60（高清）视频：以每秒60帧的1280x720彩色视频为例。所需带宽=1280（宽度）x 720（高度）x 3（每像素颜色）x 8（每像素位数）x 60（帧/秒）=1.33 Gbps。这里我们只还是使用了一个简化的情况，由于开销（帧信号等），实际带宽消耗将更高。</p>
<p>​    因此这个时候就体现出了视频压缩的作用了，当压缩到H.264时，720p60流可以以低于12Mbps的速率进行流式传输。对于H.265压缩，这个值将进一步减小。</p>
<h2 id="2-初步使用gstreamer"><a href="#2-初步使用gstreamer" class="headerlink" title="2. 初步使用gstreamer"></a>2. 初步使用gstreamer</h2><p>​    视频编码/解码是一个计算量很大的操作，最好使用专用的编码器/解码器硬件来完成。Nvidia Jetson设备配有内置的硬件编码器和解码器（分别称为NVENC和NVDEC），Jetpack带gstreamer插件，以简单的方式利用此功能。</p>
<p>​    手头有一个罗技的USB摄像头，因此可以安装v4l-utils工具：sudo apt-get install v4l-utils；要查询v4l设备（将它们连接到您的Jetson nano的USB端口后），请使用以下命令：v4l2-ctl –list-devices；查询设备支持的格式（在这种情况下为video0）：v4l2-ctl -d /dev/video0 –list-formats-ext。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信图片_20210124102527.jpg" style="zoom:30%;">

<h3 id="2-1-在屏幕上显示usb摄像头图像"><a href="#2-1-在屏幕上显示usb摄像头图像" class="headerlink" title="2.1 在屏幕上显示usb摄像头图像"></a>2.1 在屏幕上显示usb摄像头图像</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gst-launch<span class="number">-1.0</span> -ev v4l2src device=/dev/video0 ! xvimagesink</span><br></pre></td></tr></table></figure>
<h3 id="2-2-用gst-omx-进行H264硬件编码"><a href="#2-2-用gst-omx-进行H264硬件编码" class="headerlink" title="2.2 用gst-omx 进行H264硬件编码"></a>2.2 用gst-omx 进行H264硬件编码</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gst-launch-1.0 v4l2src device=&quot;/dev/video0&quot; ! &quot;video/x-raw, width=640, height=480, format=(string)YUY2&quot; ! nvvidconv ! &#x27;video/x-raw(memory:NVMM), format=(string)I420&#x27; ! omxh264enc ! &#x27;video/x-h264, stream-format=(string)byte-stream&#x27; ! h264parse ! qtmux ! filesink location=test.mp4 -e</span><br></pre></td></tr></table></figure>
<p>​    使用的usb摄像头视频是YUY2格式，然后转换格式为I420的格式，<strong>因为omxH264enc只支持这个格式</strong>，然后再使用一个264的流工具输出到filesink也就输出到test.mp4中。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/01/23/hexo%E5%8D%9A%E5%AE%A2%E5%A4%87%E4%BB%BD/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/01/23/hexo%E5%8D%9A%E5%AE%A2%E5%A4%87%E4%BB%BD/" class="post-title-link" itemprop="url">hexo博客备份</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-23 15:02:56" itemprop="dateCreated datePublished" datetime="2021-01-23T15:02:56+08:00">2021-01-23</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index"><span itemprop="name">博客搭建</span></a>
                </span>
            </span>

          
            <span id="/2021/01/23/hexo%E5%8D%9A%E5%AE%A2%E5%A4%87%E4%BB%BD/" class="post-meta-item leancloud_visitors" data-flag-title="hexo博客备份" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/01/23/hexo%E5%8D%9A%E5%AE%A2%E5%A4%87%E4%BB%BD/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/01/23/hexo%E5%8D%9A%E5%AE%A2%E5%A4%87%E4%BB%BD/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="1-为什么要备份"><a href="#1-为什么要备份" class="headerlink" title="1. 为什么要备份"></a>1. 为什么要备份</h2><p>​        Hexo的博客是静态托管的，我们之前只是把public文件夹中的静态文件push到了gitee仓库中，其他目录是没有任何备份的，如果哪一天电脑坏了，或者是误删了本地数据，文章源文件就丢失了。</p>
<h2 id="2-备份数据"><a href="#2-备份数据" class="headerlink" title="2. 备份数据"></a>2. 备份数据</h2><h3 id="2-1-先看下Hexo文件夹下有什么"><a href="#2-1-先看下Hexo文件夹下有什么" class="headerlink" title="2.1 先看下Hexo文件夹下有什么"></a>2.1 先看下Hexo文件夹下有什么</h3><ul>
<li>_config.yml：站点的配置文件，需要备份；</li>
<li>themes：主题文件夹，需要备份；</li>
<li>source：博客文章的 .md 文件，需要备份；</li>
<li>scaffolds：文章的模板，需要备份；</li>
<li>package.json：安装包的名称，需要备份；</li>
<li>.gitignore：限定在 push 时哪些文件可以忽略，需要备份；</li>
<li>.git：主题和站点都有，标志这是一个 git 项目，不需要备份；</li>
<li>node_modules：是安装包的目录，在执行 npm install 的时候会重新生成，不需要备份；</li>
<li>public：是 hexo g 生成的静态网页，不需要备份；</li>
<li>.deploy_git：同上，hexo g 也会生成，不需要备份；</li>
<li>db.json：文件，不需要备份。</li>
</ul>
<h3 id="2-2-创建版本库"><a href="#2-2-创建版本库" class="headerlink" title="2.2 创建版本库"></a>2.2 创建版本库</h3><p>​        在Hexo目录下，执行git  init</p>
<h3 id="2-3-在gitee上新建仓库"><a href="#2-3-在gitee上新建仓库" class="headerlink" title="2.3 在gitee上新建仓库"></a>2.3 在gitee上新建仓库</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210123133248.png" style="zoom:67%;">

<p>​    链接仓库的地址：<a href="mailto:&#103;&#105;&#x74;&#x40;&#x67;&#x69;&#x74;&#x65;&#101;&#x2e;&#99;&#x6f;&#109;">&#103;&#105;&#x74;&#x40;&#x67;&#x69;&#x74;&#x65;&#101;&#x2e;&#99;&#x6f;&#109;</a>:xudonglei/blog.git</p>
<h3 id="2-4-添加备份文件"><a href="#2-4-添加备份文件" class="headerlink" title="2.4 添加备份文件"></a>2.4 添加备份文件</h3><p>​     git add source/ themes/ _config.yml scaffolds/ package.json package-lock.json  .gitignore</p>
<h3 id="2-5-上传到gitee仓库"><a href="#2-5-上传到gitee仓库" class="headerlink" title="2.5 上传到gitee仓库"></a>2.5 上传到gitee仓库</h3><p>​    git commit -m “博客备份”</p>
<p>​    git remote add origin <a href="mailto:&#103;&#x69;&#x74;&#64;&#103;&#105;&#116;&#101;&#x65;&#46;&#99;&#111;&#109;">&#103;&#x69;&#x74;&#64;&#103;&#105;&#116;&#101;&#x65;&#46;&#99;&#111;&#109;</a>:xudonglei/blog.git</p>
<p>​    git push -u origin master</p>
<p>​    第一次备份完毕，以后的备份，只需要执行下面的操作：</p>
<p>​    git push origin master</p>
<p>​    这样备份完毕后，我们在另一台电脑上，只需git clone一下就行了。</p>
<h2 id="3-测试备份是否成功"><a href="#3-测试备份是否成功" class="headerlink" title="3. 测试备份是否成功"></a>3. 测试备份是否成功</h2><p>​    在另外一台笔记本上，将项目克隆到本地：git clone <a target="_blank" rel="noopener" href="https://gitee.com/xudonglei/blog.git">https://gitee.com/xudonglei/blog.git</a></p>
<p>​    然后进入blog目录下，执行下面的指令：npm  install -g  hexo， npm install    </p>
<p>​    最后按照之前的步骤写文章，提交文章即可。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/01/18/hexo%E4%B8%AD%E4%BD%BF%E7%94%A8LeanCloud%E7%BB%9F%E8%AE%A1%E6%96%87%E7%AB%A0%E9%98%85%E8%AF%BB%E6%AC%A1%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2021/01/18/hexo%E4%B8%AD%E4%BD%BF%E7%94%A8LeanCloud%E7%BB%9F%E8%AE%A1%E6%96%87%E7%AB%A0%E9%98%85%E8%AF%BB%E6%AC%A1%E6%95%B0/" class="post-title-link" itemprop="url">hexo中使用LeanCloud统计文章阅读次数</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-01-18 21:48:22" itemprop="dateCreated datePublished" datetime="2021-01-18T21:48:22+08:00">2021-01-18</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" itemprop="url" rel="index"><span itemprop="name">博客搭建</span></a>
                </span>
            </span>

          
            <span id="/2021/01/18/hexo%E4%B8%AD%E4%BD%BF%E7%94%A8LeanCloud%E7%BB%9F%E8%AE%A1%E6%96%87%E7%AB%A0%E9%98%85%E8%AF%BB%E6%AC%A1%E6%95%B0/" class="post-meta-item leancloud_visitors" data-flag-title="hexo中使用LeanCloud统计文章阅读次数" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2021/01/18/hexo%E4%B8%AD%E4%BD%BF%E7%94%A8LeanCloud%E7%BB%9F%E8%AE%A1%E6%96%87%E7%AB%A0%E9%98%85%E8%AF%BB%E6%AC%A1%E6%95%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2021/01/18/hexo%E4%B8%AD%E4%BD%BF%E7%94%A8LeanCloud%E7%BB%9F%E8%AE%A1%E6%96%87%E7%AB%A0%E9%98%85%E8%AF%BB%E6%AC%A1%E6%95%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="1-配置-LeanCloud"><a href="#1-配置-LeanCloud" class="headerlink" title="1. 配置 LeanCloud"></a>1. 配置 LeanCloud</h2><p>​        进入官网  <a target="_blank" rel="noopener" href="https://leancloud.cn/%EF%BC%8C">https://leancloud.cn/，</a> 进入右侧控制台并注册账号、验证邮箱；</p>
<p>​        创建应用，应用名称可以随便起，我就取名counter_test；</p>
<p>​        点击存储-&gt;结构化数据，点击刚刚创建的counter_test，创建Class表用来保存我们的博客访问数据，这里创建的Class名字必须为Counter，用来保证和Next主题的修改相兼容。ACL 权限选择 无限制，避免后续因为权限的问题导致次数统计显示不正常。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210118201232.png" style="zoom:67%;">

<p>​        再点击设置-&gt;应用Keys，把你的 AppID 和 AppKey 复制出来。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20210118202530.png" style="zoom:50%;">

<h2 id="2-修改主题配置文件"><a href="#2-修改主题配置文件" class="headerlink" title="2. 修改主题配置文件"></a>2. 修改主题配置文件</h2><p>​        打开 NexT 主题的 _config.yml 文件，把刚才拿到的 AppID 和 AppKey 和填入下面相应位置：</p>
<figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">leancloud<span class="emphasis">_visitors:</span></span><br><span class="line"><span class="emphasis">  enable: true</span></span><br><span class="line"><span class="emphasis">  app_</span>id: 填你的app id</span><br><span class="line">  app<span class="emphasis">_key: 填你的app key</span></span><br><span class="line"><span class="emphasis">  # Required for apps from CN region</span></span><br><span class="line"><span class="emphasis">  server_</span>url: # <span class="xml"><span class="tag">&lt;<span class="name">your</span> <span class="attr">server</span> <span class="attr">url</span>&gt;</span></span></span><br><span class="line">  # Dependencies: https://github.com/theme-next/hexo-leancloud-counter-security</span><br><span class="line">  # If you don&#x27;t care about security in leancloud counter and just want to use it directly</span><br><span class="line">  # (without hexo-leancloud-counter-security plugin), set <span class="code">`security`</span> to <span class="code">`false`</span>.</span><br><span class="line">  security: false</span><br></pre></td></tr></table></figure>
<p>​        这时再使用 hexo g、hexo d命令重新部署博客，就可以正常使用文章阅读量统计的功能了，本来以为到这边就可以了，实际部署后发现首页阅读量显示为0，并且打开文章后，阅读次数直接不显示了。</p>
<h2 id="3-修复阅读量不显示问题"><a href="#3-修复阅读量不显示问题" class="headerlink" title="3. 修复阅读量不显示问题"></a>3. 修复阅读量不显示问题</h2><p>​        找了好久，终于在百度上有其他网友遇到过相同的问题。在_config.yml配置文件中找到valine的配置，填入LeanCloud的appid与appkey，并更改为：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">valine:</span></span><br><span class="line">  <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line">  <span class="attr">appid:</span> <span class="string">你的app</span> <span class="string">id</span></span><br><span class="line">  <span class="attr">appkey:</span> <span class="string">你的app</span> <span class="string">key</span></span><br><span class="line">  <span class="attr">notify:</span> <span class="literal">false</span> <span class="comment"># Mail notifier</span></span><br><span class="line">  <span class="attr">verify:</span> <span class="literal">false</span> <span class="comment"># Verification code</span></span><br><span class="line">  <span class="attr">placeholder:</span> <span class="string">Just</span> <span class="string">go</span> <span class="string">go</span> <span class="comment"># Comment box placeholder</span></span><br><span class="line">  <span class="attr">avatar:</span> <span class="string">mm</span> <span class="comment"># Gravatar style</span></span><br><span class="line">  <span class="attr">guest_info:</span> <span class="string">nick,mail,link</span> <span class="comment"># Custom comment header</span></span><br><span class="line">  <span class="attr">pageSize:</span> <span class="number">10</span> <span class="comment"># Pagination size</span></span><br><span class="line">  <span class="attr">language:</span> <span class="string">zh-CN</span></span><br><span class="line">  <span class="attr">visitor:</span> <span class="literal">true</span> <span class="comment"># Article reading statistic</span></span><br><span class="line">  <span class="attr">comment_count:</span> <span class="literal">true</span> <span class="comment"># If false, comment count will only be displayed in post page, not in home page</span></span><br><span class="line">  <span class="attr">recordIP:</span> <span class="literal">false</span> <span class="comment"># Whether to record the commenter IP</span></span><br><span class="line">  <span class="attr">serverURLs:</span> <span class="comment"># When the custom domain name is enabled, fill it in here (it will be detected automatically by default, no need to fill in)</span></span><br><span class="line">  <span class="comment">#post_meta_order: 0</span></span><br></pre></td></tr></table></figure>
<p>​        最关键的地方在于设置 visitor: true，因为valine中的visitor兼容了前面提到的leancloud_visitors配置，故仅需要在这里设置即可。修改结束后在_config.yml配置文件中找到leancloud_visitors的配置更改为：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">leancloud_visitors:</span></span><br><span class="line">    <span class="attr">enable:</span> <span class="literal">false</span></span><br></pre></td></tr></table></figure>
<p>​        到这里就完成了浏览量的配置了。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/27/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/27/">27</a><span class="page-number current">28</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/29/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
